package com.linkhouse.service.impl;

import com.linkhouse.domain.bo.TbOrderBO;
import com.linkhouse.domain.po.TbOrder;
import com.linkhouse.domain.vo.TbOrderVO;
import com.linkhouse.mapper.OrderMapper;
import com.linkhouse.service.IndexOrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
public class IndexOrderServiceImpl implements IndexOrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<TbOrderBO> query(Long id) {


        Date dNow = new Date(); //当前时间
        Date dBefore = new Date();
        Calendar calendar = Calendar.getInstance(); //得到日历
        calendar.setTime(dNow);//把当前时间赋给日历
        calendar.add(calendar.MONTH, -3); //设置为前3月
        dBefore = calendar.getTime(); //得到前3月的时间
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置时间格式
        String defaultStartDate = sdf.format(dBefore); //格式化前3月的时间
        String defaultEndDate = sdf.format(dNow); //格式化当前时间
        System.out.println("前3个月的时间是：" + defaultStartDate);
        System.out.println("生成的时间是：" + defaultEndDate);
        List<TbOrderVO> orderList = orderMapper.select(id,defaultStartDate);
        List<TbOrderBO> orderBOList = new ArrayList<>();
        for (TbOrderVO tbOrder : orderList) {
            TbOrderBO bo = new TbOrderBO();
            BeanUtils.copyProperties(tbOrder,bo);
            orderBOList.add(bo);
        }

        return orderBOList;
    }
}
